<?php

	/**
	 * @see Zend_Validate_Alnum
	 */
	require_once 'Zend/Validate/Alnum.php';
	
	
	class Bike_Validate_LatinAlnum extends Zend_Validate_Alnum
	{
	    protected $_messageTemplates = array(
	        self::INVALID      => "Invalid type given. String, integer or float expected",
	        self::NOT_ALNUM    => "'%value%' contains characters which are non latin alphabetic and no digits",
	        self::STRING_EMPTY => "'%value%' is an empty string",
	    );

	    public function getPattern()
	    {
	    	return '/^[a-zA-Z0-9'.($this->getAllowWhiteSpace() ? ' ' : '').']+$/';
	    }

	    public function isValid($value)
	    {
	        if(!is_string($value) && !is_int($value) && !is_float($value))
	        {
	            $this->_error(self::INVALID);
	            return false;
	        }

	        $this->_setValue($value);

	        if('' === $this->_value)
	        {
	            $this->_error(self::STRING_EMPTY);
	            return false;
	        }

	        $status = @preg_match($this->getPattern(), $value);
	        if(false === $status)
	        {
	            $this->_error(self::NOT_ALNUM);
	            return false;
	        }

	        return true;
	    }
	}
